<?php
// ------------------------------------------------------------------------

/**
 * CodeIgniter My Form Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		Richard Grimaldo
 */

/**
 * Permet la gestion des champs de formulaire selon nos choix pour mon site
 */

// ------------------------------------------------------------------------
$CI =& get_instance();
$CI->load->helper("html");

if(!function_exists('my_diplay_form_input'))
{
	function my_diplay_form_input($label, $type_input, $input_name, $from_var, $error, $mandatory = false, $other = array())
	{
		if(function_exists("my_form_".$type_input)) {
			$fct_param = array(
							$input_name, $from_var, $label, $error, $other
						);
			return my_diplay_form_html(
					$label, $input_name, $mandatory,
					"my_form_".$type_input, $fct_param
				);
		}
	}
}

if(!function_exists('my_diplay_form_other'))
{
	function my_diplay_form_other($label, $type_input, $input_name, $from_var, $error, $mandatory = false, $other = array())
	{
		if(function_exists($type_input)) {
			$fct_param = array($input_name, $from_var, $label, $error, $other);
			return my_diplay_form_html(
					$label, $input_name, $mandatory,
					$type_input, $fct_param
				);
		}
	}
}

if(!function_exists('my_diplay_form_html'))
{
	function my_diplay_form_html($label, $input_name, $mandatory, $fct_name, $fct_param)
	{
		$html = '
			<div class="form_input">
				<div class="f_title">
					'.my_form_label($label, $input_name, $mandatory).'
				</div>
				<div class="f_input">
					'.call_user_func_array($fct_name, $fct_param).'
				</div>
			</div>';
		return $html;
	}
}

if(!function_exists('my_display_error'))
{
	function my_display_error($errors, $label)
	{
		$CI =& get_instance();
		$errors_trad = $CI->config->item('errors_trad', 'my_site');
		$errors_label = array();
		foreach($errors as $error => $param) {
			if(isset($errors_trad[$error])) {
				$errors_label[] = sprintf($errors_trad[$error], $label, $param);
			}else {
				$errors_label[] = $error;
			}
		}
		return '<span class="error"><br/>'.implode('<br />', $errors_label).'<span>';
	}
}

